package com.leetcode.LC;

public class LC1437 {
    public boolean kLengthApart(int[] nums, int k) {
        //掐头去尾，然后再遍历
        if (k == 0) {
            return true;
        }
        int b = nums.length - 1;
        while (b>=0&&nums[b] == 0) {
            b--;
        }
        int a = 0;
        while (a<nums.length&&nums[a] == 0) {
            a++;
        }
        boolean f = false;
        int count = -1;
        for (int i = a; i <= b; i++) {
            if (nums[i] == 1 && f) {
                if (count < k) {
                    return false;
                } else {
                    count = 0;
                }
            } else {
                count++;
                f = true;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new LC1437().kLengthApart(new int[]{1,0,1}, 2));
    }

}
